package cn.com.codingce.student.servlet;

import cn.com.codingce.student.service.ITeacherService;
import cn.com.codingce.student.service.impl.TeacherServiceImpl;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class DeleteTeacherServlet
 */
@WebServlet("/DeleteTeacherServlet")
public class DeleteTeacherServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       



	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		 * 删除
		 */
		request.setCharacterEncoding("utf-8");
		/*
		 * 接受前端传来的 学号
		 */
		int no = Integer.parseInt(request.getParameter("id"));
		ITeacherService service = new TeacherServiceImpl();
		
		boolean result = service.deleteTeacherById(no);
		
		response.setContentType("text/html; charset=UTF-8");
		response.setCharacterEncoding("utf-8");
		if(result){
			//response.getWriter().println("删除成功!" + result);
			/*
			 * 删除完重新查询
			 */
			response.sendRedirect( "querybypage" ); 
		}else{
			response.getWriter().println("删除失败!" + result);
		}
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
